package com.wyt.controller.tupianController;


import com.wyt.dao.ToutstorageDetailMapper;
import com.wyt.entity.StaticTu1Util;
import com.wyt.entity.ToutstorageDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class Bookchart {

    @Autowired
    private ToutstorageDetailMapper toutstorageDetailMapper;

    @RequestMapping("/statisc/tu1")
    @ResponseBody
    private List<StaticTu1Util> findTu1(){
        List<ToutstorageDetail> list1= toutstorageDetailMapper.findAllByPublisherAndCount();
        List<StaticTu1Util> list=new ArrayList<>();
        for (ToutstorageDetail t1:list1
             ) {
            StaticTu1Util s1=new StaticTu1Util(t1.getPublisher(),t1.getSumCount());
            list.add(s1);
        }
        return list;
    }

    @RequestMapping("/statisc/tu2")
    @ResponseBody
    private List<StaticTu1Util> findTu2(){

        List<ToutstorageDetail> list1= toutstorageDetailMapper.findAllByBookTypeAndCount();
        List<StaticTu1Util> list=new ArrayList<>();

        for (ToutstorageDetail t1:list1
        ) {
            StaticTu1Util s1=new StaticTu1Util(t1.getBooktype(),t1.getSumCount());
            list.add(s1);
        }
        return list;
    }

    @RequestMapping("/statisc/tu3")
    @ResponseBody
    private List<StaticTu1Util> findTu3(){
        List<ToutstorageDetail> list1= toutstorageDetailMapper.findAllBookNameAndCount();
        List<StaticTu1Util> list=new ArrayList<>();
        for (ToutstorageDetail t1:list1
        ) {
            String str=t1.getBookname()+" "+t1.getBookid();
            StaticTu1Util s1=new StaticTu1Util(str,t1.getSumCount());
            list.add(s1);
        }
        return list;
    }


}
